package com.itheima.service.impl;

import com.itheima.dao.UserDao;
import com.itheima.po.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    UserDao userDao;

    public int createUser(User user){
        //用户名查重
        if(userDao.ifUsernameRepeat(user) == 1){
            System.out.println("用户名重复!");
            return 0;
        }
        //用户电话查重
        if(userDao.ifPhoneRepeat(user) == 1){
            System.out.println("电话重复!");
            return 0;
        }
        //创建该用户
        userDao.createUser(user);
        return 1;
    }

    public int userLogin(User user){
        User data_user = userDao.selectUsernameAndPassword(user);
        if(!data_user.equals(user)){
            return 0;
        }
        return 1;
    }

    public User findUserByUsername(String name){
        //System.out.println("找到的用户：" + userDao.findUserByUsernaem(name));
        return userDao.findUserByUsernaem(name);
    }


}
